<?php
include_once('../config/config.php');
include_once('../config/db.php');
include_once('../class/db.class.php');	
error_reporting(0);
if($_GET['a'] == 'click'){
	$T = is_numeric($_GET['t']) ? $_GET['t'] : 0;
	$I = is_numeric($_GET['i']) ? $_GET['i'] : 0;
	$V = is_numeric($_GET['v']) ? $_GET['v'] : 0;
	$tN = $fN = NULL; 
	if($I != 0){
		switch ($T){
			case 0 : $tN = $dbprefix.'article'; $fN = 'ArticleClick'; break;
			case 1 : $tN = $dbprefix.'news'; $fN = 'NewsClick'; break;
			case 2 : $tN = $dbprefix.'product'; $fN = 'ProductClick'; break;
		}		
		$db = new db();
		$SQL = "UPDATE `{$tN}` SET `{$fN}` = (`{$fN}`+1) WHERE `ID` = '{$I}' LIMIT 1;";
		$db -> ExecuteSQL($SQL);
		if($V != 0){
			$SQL = "SELECT `{$fN}` FROM `{$tN}` WHERE `ID` = '{$I}'";
			$C = $db -> SelectSQL($SQL,0);
			echo "document.write('{$C[0][0]}');";
		}
	}
}
if($_POST['a'] == 'agree'){
	@include_once("../config/language_{$_POST['Lang']}.php");
	if(!is_numeric($_POST['Lang']) || !is_numeric($_POST['isagree']) || !is_numeric($_POST['module']) || !is_numeric($_POST['id'])){
		die("var result = '{$Warning[7]}';");
	}
	$cookiename = "AGREE_{$_POST['module']}_{$_POST['Lang']}_{$_POST['id']}";
	if($_COOKIE[$cookiename] != 'songcms'){
		$tN = $fN = $sN = NULL; 
		switch ($_POST['module']){
			case 0 : $tN = "{$dbprefix}article"; $fN = $_POST['isagree'] == 1 ? 'ArticleAgree' : 'ArticleDisagree'; $sN = '`ArticleAgree`,`ArticleDisagree`'; break;
			case 1 : $tN = "{$dbprefix}product"; $fN = $_POST['isagree'] == 1 ? 'ProductAgree' : 'ProductDisagree'; $sN = '`ProductAgree`,`ProductDisagree`'; break;
			case 2 : $tN = "{$dbprefix}news"; $fN = $_POST['isagree'] == 1 ? 'NewsAgree' : 'NewsDisagree'; $sN = '`NewsAgree`,`NewsDisagree`'; break;
			default : die("var result = '{$Warning[7]}';"); break;
		}
		$db = new db();
		$SQL = "UPDATE `{$tN}` SET `{$fN}` = (`{$fN}` + 1) WHERE `ID` = '{$_POST['id']}' LIMIT 1;"; 
		if($db -> ExecuteSQL($SQL)){
			@setcookie($cookiename,'songcms',time()+31536000);
			$SQL = "SELECT {$sN} FROM `{$tN}` WHERE `ID` = '{$_POST['id']}'"; 
			$C = $db -> SelectSQL($SQL,0);
			if ($WebStaticHTML == 1){ 
				include_once('../class/html.class.php');
				switch ($_POST['module']){
					case 0 : $_GET['Action'] = 'Page'; $ps = 7; break;
					case 1 : $_GET['Action'] = 'Product'; $ps = 9; break;
					case 2 : $_GET['Action'] = 'News'; $ps = 11; break;
				}			
				$_GET['Lang'] = $_POST['Lang'];
				$html = new html();
				$html -> StartID = $html -> EndID = $_POST['id'];
				$html -> HTMLPath = '../';
				$html -> Paths($ps);
				$html -> MakeAndURL();
			}			
			die("var result = '1'; var agree = {$C[0][0]}; var disagree = {$C[0][1]};");
		} else {
			die("var result = '{$Warning[18]}';"); 
		}
	} else {
		die("var result = '{$Warning[27]}';"); 
	}
}
if($_POST['a'] == 'login'){
	include_once("../config/language_{$_POST['Lang']}.php");
	include_once('../class/user.class.php');
	if(empty($_POST['username']) || empty($_POST['password'])) die("var result = '{$Html['pUser']}';"); 
	$user = new user();
	switch($user->scLogin(trim($_POST['username']),trim($_POST['password']),'yes','yes')){
		case 9: 
			@setcookie('Example_auth','songcms',time()+2592000,'/'); 
			echo "var result = '1';"; 
			if($_POST['param'] == 1){ 
				die("var welcome = '&nbsp;&nbsp; {$Html['Welcome']}{$_POST['username']}';"); 
			}
			break;
		case 1: die("var result = '{$Warning[2]}';"); break; 
		case 2: die("var result = '{$Warning[3]}';"); break;	
		case 3: die("var result = '{$Warning[4]}';"); break; 
		case 4: die("var result = '{$Warning[5]}';"); break; 
		default: die("var result = '{$Warning[1]}';"); break; 
	}
}
?>